package com.mc.lp.database.entity.helper;

import java.util.Date;

import com.mc.lp.database.entity.ExtraAcademicRecordEntity;
import com.mc.lp.shared.util.DateUtil;
import com.mc.lp.shared.vo.ExtraAcademicRecordVO;
/*
 * @author aphanda
 * @date Sep 28, 2014
 * @time 12:40:48 AM
 */
/**
 * helper class to parse extra academic record into entity and vica versa
 * 
 *
 */
public class ExtraAcademicRecordHelper implements IEntityHelper<ExtraAcademicRecordEntity, ExtraAcademicRecordVO>{

	@Override
	public ExtraAcademicRecordVO getVO(ExtraAcademicRecordEntity entity) {
		
		ExtraAcademicRecordVO vo = new ExtraAcademicRecordVO();
		vo.setNewRow(false);
		vo.setSid(entity.getId());
		vo.setAllIndiaRank(entity.getAllIndiaRank());
		vo.setCertificateAttachmentId(entity.getCertificateAttachmentId());
		vo.setCertificationId(entity.getCertificationId());
		//en.setCreatedDate(createdDate);
		// AP date formatter
		if(entity!=null)
		vo.setDated(DateUtil.convertDate2StringDate(entity.getDated(), "dd-MMMM-yyyy"));
		vo.setGradeId(entity.getGradeId());
		vo.setSchoolRank(entity.getSchoolRank());
		vo.setStateRank(entity.getStateRank());
		vo.setAttributeWeightage(entity.getAttributeWeightage());
		vo.setRemark(entity.getRemark());
		return vo;
	}

	@Override
	public ExtraAcademicRecordEntity getEntity(ExtraAcademicRecordVO vo) {

		ExtraAcademicRecordEntity en = new ExtraAcademicRecordEntity();
		setEntity(vo, en);
		return en;
	}

	@Override
	public void setEntity(ExtraAcademicRecordVO vo, ExtraAcademicRecordEntity entity) {
		if (!vo.isNewRow())
			entity.setId(vo.getSid());
		entity.setAllIndiaRank(vo.getAllIndiaRank());
		entity.setCertificateAttachmentId(vo.getCertificateAttachmentId());
		entity.setCertificationId(vo.getCertificationId());
		// en.setCreatedDate(createdDate);
		entity.setRemark(vo.getRemark());
		entity.setGradeId(vo.getGradeId());
		entity.setModifiedDate(new Date());
		entity.setSchoolRank(vo.getSchoolRank());
		entity.setStateRank(vo.getStateRank());
		entity.setAttributeWeightage(vo.getAttributeWeightage());
		try {
			entity.setDated(DateUtil.convertString2Date(vo.getDated(), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"));
		} catch (Exception pe) {
			entity.setDated(DateUtil.convertString2Date(vo.getDated(), "dd-MMM-yyyy"));
		}
	}
}
